//
//  YBNormalTreeTableViewCell.m
//  GongXinDangJian
//
//  Created by apple on 17/12/12.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "YBNormalTreeTableViewCell.h"

@interface YBNormalTreeTableViewCell ()
@property (nonatomic , strong) UILabel * cellTitleLabel;

@property (nonatomic , strong) UIImageView * openImageView;

@property (nonatomic , strong) UIImageView * selectImageView;
@end

@implementation YBNormalTreeTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self ybInitMyCell];
    }
    return self;
}


-(void)ybInitMyCell{
    [self.contentView addSubview:self.cellTitleLabel];
    [self.contentView addSubview:self.openImageView];
    [self.contentView addSubview:self.selectImageView];
    UIView * lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
    lineView.backgroundColor = [UIColor themeGrayColor];
    [self.contentView addSubview:lineView];
    
    lineView.sd_layout.leftSpaceToView(self.contentView , 0).rightSpaceToView(self.contentView , 0).bottomSpaceToView(self.contentView , 0).heightIs(1);
}

-(void)setModel:(YBNormalTreeModel *)model
{
    _model = model;
    if (model.children.count == 0) {
        self.openImageView.hidden = YES;
        self.selectImageView.hidden = NO;
        self.isSelect = model.isSelect;
    }
    else{
        self.selectImageView.hidden = YES;
        self.openImageView.hidden = NO;
        self.isOpen = model.isOpen;
    }
    CGFloat titleHeight = model.titleHeight;
    self.openImageView.frame = CGRectMake(ItemWidth * 15 + ItemWidth * 44 * self.level, (titleHeight - ItemWidth * 44) / 2, ItemWidth * 44, ItemWidth * 44);
    self.cellTitleLabel.frame = CGRectMake(ItemWidth * 74  + ItemWidth * 44 * self.level, 0, [UIScreen zj_screenWith] - ItemWidth * 236 - (ItemWidth * 44 * self.level), titleHeight);
    self.selectImageView.frame = CGRectMake([UIScreen zj_screenWith] - ItemHeight * 132, (titleHeight - ItemWidth * 42) / 2, ItemWidth * 42, ItemWidth * 42);
    self.cellTitleLabel.text = model.name;
}

-(UILabel *)cellTitleLabel
{
    if (!_cellTitleLabel) {
        _cellTitleLabel = [ToolClass creatLabelWithFrame:CGRectMake(ItemWidth * 74, 0, [UIScreen zj_screenWith] - ItemWidth * 236, ItemHeight * 80) font:16 textColor:[UIColor textBlackColor] text:@""];
    }
    return _cellTitleLabel;
}


-(UIImageView *)openImageView
{
    if (!_openImageView) {
        _openImageView = [[UIImageView alloc]initWithFrame:CGRectMake(ItemWidth * 15, (ItemHeight * 80 - ItemWidth * 44) / 2, ItemWidth * 44, ItemWidth * 44)];
        _openImageView.image = [UIImage imageNamed:@"jiantou_r"];
    }
    return _openImageView;
}

-(UIImageView *)selectImageView
{
    if (!_selectImageView) {
        _selectImageView = [[UIImageView alloc]initWithFrame:CGRectMake([UIScreen zj_screenWith] - ItemHeight * 132, (ItemHeight * 80 - ItemWidth * 42) / 2, ItemWidth * 42, ItemWidth * 42)];
        _selectImageView.image = [UIImage imageNamed:@"list_select"];
    }
    return _selectImageView;
}


-(void)setIsOpen:(BOOL)isOpen
{
    _isOpen = isOpen;
    if (isOpen) {
        self.openImageView.image = [UIImage imageNamed:@"jiantou_d"];
    }
    else{
        self.openImageView.image = [UIImage imageNamed:@"jiantou_r"];
    }
}

-(void)setIsSelect:(BOOL)isSelect
{
    _isSelect = isSelect;
    if (isSelect) {
        self.selectImageView.image = [UIImage imageNamed:@"list_selected"];
    }
    else{
        self.selectImageView.image = [UIImage imageNamed:@"list_select"];
    }
}



@end
